#include "pm/tag.h"

using namespace pm;

const wxString Tag::TABLE_NAME = wxT("tags");

Tag::Tag(wxSQLite3ResultSet& res)
: db::Object(res)
, m_name(res.GetString(wxT("name")))
{
	m_colour.Set(res.GetString(wxT("colour")));
}

db::update_value_type Tag::prepare_insert(wxSQLite3Database& db)
{
	wxSQLite3Statement stmt = db.PrepareStatement("insert into tags values(null, ?, ?)");
	stmt.Bind(1, m_name);
	stmt.Bind(2, m_colour.GetAsString(wxC2S_HTML_SYNTAX));
	return db::update_value_type(true, stmt);
}

db::update_value_type Tag::prepare_update(wxSQLite3Database& db)
{
	wxSQLite3Statement stmt = db.PrepareStatement("update tags set name = ?, colour = ? where id = ?");
	stmt.Bind(1, m_name);
	stmt.Bind(2, m_colour.GetAsString(wxC2S_HTML_SYNTAX));
	stmt.Bind(3, id());
	return db::update_value_type(true, stmt);
}
